/***********************************************************************
** Copyright (C) 2011 Anthony Naddeo <anthony.naddeo@gmail.com>
**
** This file is part of LinkedUp
**
** LinkedUp is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 3 of the License, or
** (at your option) any later version.
**
** LinkedUp is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this package; If not, see <http://www.gnu.org/licenses/>.
**
***********************************************************************/
import QtQuick 1.1
import com.meego 1.0
import "../components"

MyPage {
	id: root
	anchors.fill: parent
	title: "News"

	tools: ToolBarLayout {
		ToolIcon { platformIconId: "toolbar-view-menu";
			anchors.right: parent===undefined ? undefined : parent.right
			onClicked: (myMenu.status == DialogStatus.Closed) ? myMenu.open() : myMenu.close()
		}
		ToolIcon { platformIconId: "toolbar-back";
			anchors.left: parent===undefined ? undefined : parent.left
			visible: pageStack ? pageStack.depth > 1 ? true : false : false
			onClicked: {
				if(pageStack.depth > 1)
					pageStack.pop()
			}
		}

	}

	property string searchString

	onGetFinished: model.xml = responseText
	Component.onCompleted: {
		if(searchString){
			get("http://news.google.com/news?pz=1&ned=us&hl=en&output=rss&q=" + searchString)
		}
		else if(User.numFollowing()){
			get(User.getCompanyQuery())
		}

		else
			var obj = noFollows.createObject(root)
	}

//	imgSource: "qrc:///qml/images/gnews.png"

	NewsModel{id: model}

	ListView{
		anchors.fill: parent
		anchors.topMargin: borderHeight
		spacing: 20
		cacheBuffer: 10000
		model: model
		delegate: NewsDelegate{
			width: root.width
		}
	}

	Component{
		id: noFollows
		Label {
			text: "You are not following any companies.\n\nYou can search for companies on the home page and follow them there"
			font.pixelSize: 24
			width: parent.width
			anchors.verticalCenter: parent.verticalCenter
			wrapMode: Text.Wrap
			horizontalAlignment: Text.AlignHCenter

			Image {
				source: "qrc:///qml/images/star-off.png"
				anchors.bottom: parent.top
				anchors.margins: 20
				anchors.horizontalCenter: parent.horizontalCenter
				smooth: true
				scale:  1.2
			}
		}
	}

}
